<?php

 /*************************************************\
    TV-Program
    Version: 2.5
    Author: Dmitri M. Furmanoff
    E-mail: furik@mail.ru
    \*************************************************/

    /*************************************************\
    Компонент: Телепрограммы
    Версия: 2.5
    Автор: Дмитрий Фурманов
    E-mail: furik@mail.ru
    \*************************************************/

defined ('_VALID_MOS') or die('Доступ к файлу запрещен.');

global $database, $mosConfig_absolute_path,$mosConfig_offset, $a_weekl, $my, $mosConfig_live_site;

$delold=mosGetParam($_REQUEST,"delold",0);
$week=mosGetParam($_REQUEST,"week",0);


$mostime=time()+($mosConfig_offset*60*60);
$params = & new mosParameters( '' );
$params->def( 'back_button', $mainframe->getCfg( 'back_button' ));
$params->def( 'popup', false );

require_once($mosConfig_absolute_path."/administrator/components/com_tv/config.tv.php");

$is_editor = (strtolower($my->usertype) == 'editor' || strtolower($my->usertype) == 'administrator' || strtolower($my->usertype) == 'super administrator');

if(file_exists($mosConfig_absolute_path.'/components/com_tv/languages/'.$mosConfig_lang.'.php'))
 {
  require_once($mosConfig_absolute_path.'/components/com_tv/languages/'.$mosConfig_lang.'.php');
} else {
   require_once($mosConfig_absolute_path.'/components/com_tv/languages/russian.php');
}


$SearchString = mosGetParam( $_REQUEST, 'SearchString','' ); 
$task =  mosGetParam( $_REQUEST ,'task', '' ); 
$Channel =  mosGetParam( $_REQUEST ,'Channel', '' ); 

$day =  mosGetParam( $_REQUEST ,'day', '' );
$Reminder=mosGetParam( $_REQUEST ,'Reminder', '' );
$ShowComments=mosGetParam( $_REQUEST ,'ShowComments', null );
$week=mosGetParam( $_REQUEST ,'week', '' );
$delold=mosGetParam( $_REQUEST ,'delold', '' );
function SearchForm ()
{
 global $database, $pathlogo, $showanons, $mostime, $a_weeks, $mosConfig_live_site;
?>
<script language="JavaScript">
<!--
function set(how){
for (i = 0; i < document.forms['tv_form'].elements.length; i++)
     {
         var item = document.forms['tv_form'].elements[i];
	     if (item.name == "Channel[]")  {
		     item.checked = how;
		 };
	 }
}
//-->
</script>

<form action="<?php sefRelToAbs("index.php?option=com_tv");?>" method="POST" name="tv_search">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr align="center">
<td>
<input type="text" name="SearchString" value="*" width="50" class="inputbox">
<input type=hidden name=task value='search'>
<input type=submit class="button" value="<?php echo _TV_BUTTONSEARCH;?>">
</td>
</tr>
</table>
</form>
<form action="<?php sefRelToAbs("index.php?option=com_tv");?>" method="POST" name="tv_form">
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr><td>
<table border="0" cellspacing="1" cellpadding="3" width="100%">
<tr align="center" class="sectiontableentry2">
<?php
/*for($i=0;$i<7;$i++)
 echo "<th>".$a_weeks[$i]."</th>";
*/
?>
</tr><tr class="sectiontableentry1">
<?php
$today=getdate($mostime);
$dayofweek = $today['wday']; 
$dayofweek=$dayofweek?$dayofweek:7;
$timestamp = mktime(0,0,0,$today['mon'],$today['mday']-$dayofweek+1,$today['year']); 
for ($i=0; $i<7; $i++) {
if($dayofweek==$i+1)
  echo "<td valign=\"middle\" align=\"center\">".$a_weeks[$i]."<br /><input type=\"Checkbox\" name=\"day[]\" value=\"".($i+1)."\" checked><b>".date("d.m",$timestamp)."</b></td>";
else  
  echo "<td valign=\"middle\" align=\"center\">".$a_weeks[$i]."<br /><input type=\"Checkbox\" name=\"day[]\" value=\"".($i+1)."\">".date("d.m",$timestamp)."</td>";

$timestamp = mktime(0,0,0,$today['mon'],$today['mday']-$dayofweek+$i+2,$today['year']); 
}						
?>
</tr>
</table>
<?php $database->setQuery( "SELECT * FROM #__tvchannels WHERE published=1 ORDER BY ordering" );
 $rows=$database->loadObjectList();
 $row_cnt=count($rows);
 $i=0;

?>
<table border="0" cellspacing="1" cellpadding="0" width="100%">
<tr><td>
<input type="checkbox" onClick=set(checked)>
<?php
echo _TV_ALLCHAN;
?>
</td></tr>
</table>
<table border="0" cellspacing="1" cellpadding="3" width="100%" class="contentpane">
<?php do{ 
echo '<tr class="sectiontableentry'.($i/3 % 2 +1).'" height=35  valign=middle>';
for($j=0;$j<3;$j++) {
?>
<td width=33%>
<?php if($i<$row_cnt) 
{
if(strlen($rows[$i]->channellogo))
  echo "<img src='$mosConfig_live_site/$pathlogo/".$rows[$i]->channellogo."' border=0 width=40 height=32 align=\"absmiddle\" vspace=2>";
else
   echo "<img src='$mosConfig_live_site/images/blank.png' border=0 width=40 height=32 align=\"absmiddle\" vspace=2>";
echo "<input type=\"Checkbox\" class=radio name=\"Channel[]\" value=\"".$rows[$i]->cid."\"><a href=".sefRelToAbs("index.php?option=com_tv&task=channel&cid=".$rows[$i]->cid).">".$rows[$i++]->channelname."</a>"; 
  }
?>
</td>
<?php
}
?>
</tr>
<?php
}while($i<$row_cnt);
?>
</td></tr>
</table>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center" class="contentpane">
<?php
 if($showanons){?>
<tr><td>
<input type="Checkbox" name="ShowComments" >
<?php
echo _TV_SHOWANONS;
?>
</td></tr>
<?php } ?>
</table>
<input type=hidden name=task value='show'>
<center><input type=submit class="button" value="<?php echo _TV_BUTTONSHOW;?>"></center>
</form>
<?php
}

function UpdateForm ()
{
  echo "<br />";
  echo "<form action=".sefRelToAbs("index.php?option=com_tv")." method='post' name='UpdateForm' enctype='multipart/form-data'>";
  echo "<input type='hidden' name='task' value='update' />";
  echo "<table cellpadding='4' cellspacing='0' border='0' width='100%' class='moduletable'><tr><td colspan='2' width='100%' class='componentheading'>"._TV_LOADHEAD."</td></tr>";
  echo "<tr><td align='left' width='30%'>"._TV_PACK."</td><td><input type='file' name='zippack' accept='application/zip, application/x-zip-compressed'></td>";
  echo "</tr><tr>";
  echo "<td align='left'><br><input type='radio' name='week' value='0' checked />"._TV_CURWEEK." </td><td align='left'><br><input type='radio' name='week' value='1' />"._TV_NEXTWEEK."</td>";
  echo "</tr><tr>";
  echo "<td colspan='2' align='left'><br><input type='Checkbox' name='delold' value='1' checked />"._TV_CLEARDB."</td>";
  echo "</tr><tr>";
  echo "<td colspan='2' align='center'><br><input class='button' type='submit' value='"._TV_LOAD."' /></td>";
  echo "</tr>";
  echo "</table></form>";
}

function main ()
{
global $is_editor, $frontupdate;
SearchForm();
if($is_editor && $frontupdate)
  UpdateForm();
}
?>
<table	width="100%" class="contentpaneopen">
<tr><td><div  class=componentheading>
<?php
echo _TV_NAME;
?></div></td></tr>
<tr>
<td>
<?php

switch ($task) {
    case 'show':
        include('components/com_tv/sub_show.php');
        break;
    case 'search':
        include('components/com_tv/sub_search.php');
        break;
    case 'reminder':
        include('components/com_tv/sub_reminder.php');
        break;
    case 'channel':
        include('components/com_tv/sub_channel.php');
        break;
    case 'update':
        require_once($mosConfig_absolute_path.'/administrator/components/com_tv/sub_update.php');
	////
	 ignore_user_abort(TRUE); 
	@ini_set("max_execution_time","600");

	$dir=$mosConfig_absolute_path."/administrator/components/com_tv/program/";
	if (file_exists($mosConfig_absolute_path."/administrator/classes/pclzip.lib.php")) {
                        require_once($mosConfig_absolute_path."/administrator/classes/pclzip.lib.php"); 
               }
    	else {
	          require_once($mosConfig_absolute_path."/administrator/includes/pcl/pclzip.lib.php");
           	}
	$file=$_FILES['zippack'];
	$zipfile = new PclZip($file[tmp_name]);
	$ziplist = $zipfile->listContent();
              $zipfile->extract($p_path=$dir);

              GetProgram($dir,$week,$delold);
      
	  break;
	default: main();
};
?>
</td>
</tr>
<tr><td align='center'><div class="small"><?php echo $programcopy;?></div></td></tr>
<?php if($componentcopy){?>
 <tr><td align='center'><div class="small"><b>TV Programm </b><br /> Copyright by Dmitri M. Furmanoff</div></td></tr>
<tr><td align='center'><div class="small">Адаптировано для Joostina CMS - ssmol</div></td></tr>
<?php } ?>
</table>



